package org.zhxy.core.quality.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.zhxy.entity.quality.Classes;

import java.util.List;
import java.util.Map;

@Mapper
public interface ClassesMapper extends BaseMapper<Classes> {

    @Select("<script> SELECT cc.* " +
            "FROM qu_classes cc " +
            "WHERE cc.`sub_school_id` IN ( " +
            "SELECT DISTINCT d.`sub_school_id` FROM sc_department d  WHERE d.sub_school_id IN ( " +
            "SELECT DISTINCT d.sub_school_id " +
            "FROM sc_teacher t, sc_teacher_department td ,sc_department d " +
            "WHERE t.`id` = td.`teacher_id` " +
            "AND td.`department_id` = d.`id` " +
            "AND td.`status` = '1' " +
            "AND t.`id` = #{map.id} )) " +
            "ORDER BY cc.`start_time` DESC " +
            "LIMIT #{map.page},#{map.size} " +
            "</script>")
    List<Classes> getClassesList(@Param("map") Map<String, Object> map);

    @Select("<script> SELECT COUNT(0) " +
            "FROM qu_classes cc " +
            "WHERE cc.`sub_school_id` IN ( " +
            "SELECT DISTINCT d.`sub_school_id` FROM sc_department d  WHERE d.sub_school_id IN ( " +
            "SELECT DISTINCT d.sub_school_id " +
            "FROM sc_teacher t, sc_teacher_department td ,sc_department d " +
            "WHERE t.`id` = td.`teacher_id` " +
            "AND td.`department_id` = d.`id` " +
            "AND td.`status` = '1' " +
            "AND t.`id` = #{map.id} )) </script>")
    long getTotal(@Param("map") Map<String, Object> map);
}
